/**
 * 添加或者修改页面
 */
var DictInfoDlg = {
    data: {
        code: "",
        name: "",
        parentId: "",
        dictDescribe: "",
        dictValue: "",
        images: "",
        createTime: "",
        updateTime: ""
    }
};

layui.use(['form', 'admin', 'ax', 'upload'], function () {
    var $ = layui.jquery;
    var $ax = layui.ax;
    var form = layui.form;
    var admin = layui.admin;
    var upload = layui.upload;

    //让当前iframe弹层高度适应
    admin.iframeAuto();

    //表单提交事件
    form.on('submit(btnSubmit)', function (data) {
        var ajax = new $ax(Feng.ctxPath + "/tDict/addItem", function (data) {
            if (data.code == 200) {

                Feng.success("添加成功！");
            }else{
                Feng.error("添加失败！" + data.message)
            }

            //传给上个页面，刷新table用
            admin.putTempData('formOk', true);

            //关掉对话框
            admin.closeThisDialog();

        }, function (data) {
            Feng.error("添加失败！" + data.message)
        });
        data.field.parentId = Feng.getUrlParam("parentId");
        ajax.set(data.field);
        ajax.start();

        return false;
    });

    /**
     * 图片上传
     */
    upload.render({ //允许上传的文件后缀
        elem: '#test1'
        , url: Feng.ctxPath + '/upload/uploads'
        , accept: 'file' //普通文件
        , exts: 'jpg|png|jpeg' //只允许上传压缩文件
        , done: function (res) {
            if (res.code == 200) {
                $("input[name=images]").val(res.data.msg)
                layui.$('#demo1').attr('src', res.data.msg);
                layer.msg('上传成功');
            } else {
                layer.msg('上传失败');
            }
        }
    });

});